﻿Imports System.Data.OleDb
Imports DTO
Public Class TacGiaDAO
    Public Function LayThongTinTacGiaTheoMa(ByVal maTacGia As Integer) As TacGiaDTO
        Dim sql As String = "select MaTacGia , TenTacGia from TACGIA where MaTacGia = " & maTacGia.ToString()
        DataProvider.OpenConnecttion()
        Dim reader As OleDbDataReader = DataProvider.ExecSelect(sql)
        reader.Read()
        Dim tg As New TacGiaDTO
        tg.MaTacGia = reader.GetInt32(0)
        tg.TenTacGia = reader.GetString(1)
        DataProvider.CloseConnect()

        Return tg
    End Function

    Public Function LayDSTacGia() As List(Of TacGiaDTO)
        Dim sql As String = "select MaTacGia , TenTacGia from TACGIA"
        DataProvider.OpenConnecttion()
        Dim reader As OleDbDataReader = DataProvider.ExecSelect(sql)
        Dim dsTG As New List(Of TacGiaDTO)

        While reader.Read()
            Dim tg As New TacGiaDTO()
            tg.MaTacGia = reader.GetInt32(0)
            tg.TenTacGia = reader.GetString(1)
            dsTG.Add(tg)
        End While
        DataProvider.CloseConnect()
        Return dsTG
    End Function

    Public Function CapNhatTacGia(ByVal sql As String) As Integer
        DataProvider.OpenConnecttion()
        Dim kq As Integer = DataProvider.ExecInsert(sql)
        DataProvider.CloseConnect()
        Return kq
    End Function

    Public Function ThemTacGia(ByVal sql As String) As Integer
        DataProvider.OpenConnecttion()
        Dim kq As Integer = DataProvider.ExecInsert(sql)
        DataProvider.CloseConnect()
        Return kq
    End Function
End Class
